package com.struts2.service;

import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

//import javax.management.Query;




import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;

import com.hibernate.HibernateUtil;
import com.struts2.model.Category;
import com.struts2.model.Color;
import com.struts2.model.Designer;
import com.struts2.model.Gender;
import com.struts2.model.Invoice;
import com.struts2.model.Invoice_item;
import com.struts2.model.Product_item;
import com.struts2.model.Product_line;
import com.struts2.model.Season;
import com.struts2.model.Size;
import com.struts2.model.Type;





import org.hibernate.Query;


public class InvoiceService {

	@SuppressWarnings("unchecked")
	public List<Invoice> Invoice(List<Invoice>invoice )
	{	
		SessionFactory sF = new AnnotationConfiguration().configure()
				.buildSessionFactory();
		Session session = sF.openSession();
		session.beginTransaction();
		
		Criteria criteria = session.createCriteria(Invoice_item.class,
				"invoice_item");
		criteria.createAlias("invoice_item.invoice", "invoice");
		

		criteria.setProjection(Projections.distinct(Projections
				.projectionList()

				.add(Projections.property("invoice"))));

		
		invoice = (List<Invoice>) criteria.list();
		
		session.getTransaction().commit();
		session.close();
		sF.close();
		return invoice;
		
	}
	

	@SuppressWarnings("unchecked")
	public List<Invoice_item> InvoiceItem(List<Invoice_item>invoice_items)
	{
		SessionFactory sF = new AnnotationConfiguration().configure()
				.buildSessionFactory();
		Session session = sF.openSession();
		session.beginTransaction();
		
		Criteria criteria = session.createCriteria(Invoice_item.class);
		invoice_items = (List<Invoice_item>) criteria.list();
		

		session.getTransaction().commit();
		session.close();
		sF.close();
		return invoice_items;
	}



}
